import { defineAsyncComponent } from 'vue'

import { UseAppConfigStore } from './AppStore.js'

export default {
    install: async function (app) {
        app.AddRouter([
            {
                path: '/app',
                name: 'AppHome',
                component: () => import('./Home/index.vue'),
                redirect: '/app/home',
                children: [{
                    path: '/app/home',
                    name: 'AppMain',
                    component: () => import('./Home/AppMain/index.vue'),
                }, {
                    path: '/app/PluginManager',
                    name: 'AppPluginManager',
                    component: () => import('./Home/PluginManager/index.vue'),
                }]
            },
            {
                path: '/app-:appId(.*)',
                name: 'AppLayout',
                component: () => import('./Manage/index.vue'),
                redirect: to => {
                    return { name: 'AppAdmin', params: to.params }
                },
                children: [{
                    path: '/app-:appId(.*)/admin',
                    name: 'AppAdmin',
                    component: () => import('./Manage/Page/Page.vue'),
                    children: [{
                        path: '/app-:appId(.*)/admin/form-:formId(.*)',
                        name: 'AppAdminForm',
                        component: () => import('./Manage/Page/Page-Content.vue'),
                    }]
                }, {
                    path: '/app-:appId(.*)/admin/integration',
                    name: 'AppIntegration',
                    component: () => import('./Manage/Integration/Integration.vue')
                }, {
                    path: '/app-:appId(.*)/admin/setting',
                    name: 'AppSetting',
                    component: () => import('./Manage/Setting/Setting.vue')
                }]
            },
        ]);

        const AppConfig = UseAppConfigStore();

        app.RegistPluginEvent('App.AddConfig', function (Data) {
            AppConfig.AddConfig(Data)
        });
        // 注册组件
        app.RegistPluginCompontent('App.TreeItem', () => import('./Button/FileTreeComp.vue'))

    }
}